<?xml version="1.0" encoding="UTF-8" ?>
<!--
 *************************************************************************
 * The contents of this file are subject to the Openbravo Public License 
 * Version 1.1 (the "License"), being the Mozilla Public License 
 * version 1.1  with a permitted attribution clause ; you may not use 
 * this file except in compliance with the License. 
 * You may obtain a copy of the License at  
 * http://www.openbravo.com/legal/license.txt 
 * Software distributed under the License is distributed on an 
 * "AS IS" basis, WITHOUT WARRANTY OF  ANY KIND, either express or 
 * implied. See the License for the specific language governing rights 
 * and  limitations under the License. 
 * The Original Code is Openbravo ERP. 
 * The Initial Developer of the Original Code is [Autores] and Openbravo SL 
 * All portions are Copyright (C) 2005-2006 Openbravo SL 
 * All Rights Reserved. 
 * Contributor(s): Openbravo S.L.
 ************************************************************************
-->

<project name="openbravo sources" default="compile" basedir=".">
  <property name="webTab" value="all"/>
  <property name="tab" value="%"/>
  <property name="base.language" value="${base.source}${separator}src"/>
  <property name="base.translate.structure" value="org${separator}openbravo${separator}erpWindows"/>
  <property name="client.web.xml" value="${base.client.src}${separator}web.xml"/>
  <property name="package" value="/org"/>
  <property name="extension" value="html"/>
  <property name="src" value="."/>

  <target name="init">
    <mkdir dir="${build}/src"/>
    <mkdir dir="${base.design}/design"/>
    <mkdir dir="${build.sqlc}/src"/>
    <mkdir dir="${build.AD}"/>
    <mkdir dir="${build.AD}${separator}org${separator}openbravo${separator}erpWindows"/>
    <mkdir dir="${build.AD}${separator}org${separator}openbravo${separator}erpCommon${separator}ad_actionButton"/>
    <mkdir dir="${build.AD}${separator}org${separator}openbravo${separator}erpCommon${separator}ad_callouts"/>
    <mkdir dir="${build.AD}${separator}org${separator}openbravo${separator}erpCommon${separator}reference"/>
    <mkdir dir="${build.docs}/src"/>
  </target>

  <target name="clean">
    <property name="complete" value="true"/>
    <delete includeEmptyDirs="true" failonerror="false">
      <fileset dir="${base.design}"/>
      <fileset dir="${build}/src"/>
      <fileset dir="${build.docs}/src"/>
      <fileset dir="${build.AD}"/>
      <fileset dir="${build.sqlc}/src"/>
      <fileset dir="${build.sqlc}/srcAD"/>
    </delete>
    <basename property="attach.path.filename" file="${attach.path}"/>
    <condition property="attach.path.condition" value="**/${attach.path.filename}/**" else="">
      <and>
        <contains string="${attach.path}" substring="${jakarta.context}" casesensitive="false"/>
      </and>
    </condition>
    <delete includeEmptyDirs="true" failonerror="false">
      <fileset dir="${jakarta.context}">
        <exclude name="${attach.path.condition}"/>
      </fileset>
    </delete>
    <delete file="${jakarta.home}/webapps/${context.name}.war" failonerror="false"/>
  </target>

  <target name="copy.srcClient">
    <mkdir dir="${base.client.src}"/>
    <copy todir="${basedir}" overwrite="true" failonerror="false">
      <fileset dir="${base.client.src}">
        <exclude name="**/web.xml"/>
      </fileset>
    </copy>
  </target>

  <target name="sqlc" depends="copy.srcClient">
    <java classname="org.openbravo.data.Sqlc" fork="yes" jvm="${env.JAVA_HOME}/bin/java" maxmemory="${build.maxmemory}">
      <arg line="${base.config}/dbCon5.xml .xsql . ${build.sqlc}/src"/>
      <classpath refid="project.class.path"/>
    </java>
    <copy file="${base.subversion}${separator}src${separator}buildAD.xml" tofile="${base.source}${separator}srcAD${separator}build.xml"/>
    <copy file="${base.subversion}${separator}src${separator}log4j.lcf" tofile="${base.source}${separator}srcAD${separator}log4j.lcf"/>
    <ant dir="${base.source}${separator}srcAD" target="buildAD" inheritAll="true" inheritRefs="true"/>
  </target>

  <target name="compileSqlc" depends="sqlc">
    <javac srcdir="${build.sqlc}/src:${basedir}:${build.sqlc}/srcAD/org/openbravo/erpCommon/reference" destdir="${build}/src" encoding="UTF-8" fork="true" memorymaximumsize="${build.maxmemory}" debug="${debug.level}" deprecation="on">
      <classpath refid="project.class.path"/>
    </javac>
    <javac srcdir="${build.sqlc}/srcAD" destdir="${build}/src" encoding="UTF-8" fork="true" memorymaximumsize="${build.maxmemory}" debug="${debug.level}" deprecation="on">
      <classpath refid="project.class.path"/>
    </javac>
    <javac srcdir="${build.AD}" destdir="${build}/src" encoding="UTF-8" fork="true" memorymaximumsize="${build.maxmemory}" debug="${debug.level}" deprecation="on">
      <classpath refid="project.class.path"/>
    </javac>
  </target>

  <target name="wad" depends="init">
    <java classname="org.openbravo.wad.Wad" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
      <arg line="'${base.config}' '${tab}' '${build.AD}/org/openbravo/erpWindows' '${build.AD}/org/openbravo/erpCommon' '${build.sqlc}/src' '${webTab}' '${build.AD}/org/openbravo/erpCommon/ad_actionButton' '${base.design}' '${base.translate.structure}' '${client.web.xml}' '${base.source}' '${attach.path}' '${web.url}' '${base.src}' '${complete}'"/>
      <classpath refid="project.class.path"/>
    </java>
    <antcall target="postwad" inheritall="true" inheritrefs="true"/>
  </target>
  
  <target name="postwad">
    <copy todir="${base.design}/design" >
      <fileset dir="${build.AD}" includes="**/*.xml"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${build.AD}" includes="**/*.fo"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${build.AD}" includes="**/*.html"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${build.AD}" includes="**/*.srpt"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${build.AD}" includes="**/*.jrxml"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${build.AD}" includes="**/*.jasper"/>
    </copy>
  </target>

  <target name="postsrc">
    <copy todir="${base.design}/design" >
      <fileset dir="${basedir}" includes="**/*.xml"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${basedir}" includes="**/*.fo"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${basedir}" includes="**/*.html"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${basedir}" includes="**/*.srpt"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${basedir}" includes="**/*.jrxml"/>
    </copy>
    <copy todir="${base.design}/design" >
      <fileset dir="${basedir}" includes="**/*.jasper"/>
    </copy>
    <java classname="org.openbravo.erpCommon.utility.CommandLine_CopyFiles" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
      <arg line="'${base.config}/XmlPool.xml' '${basedir}' '${base.design}' 'xml' 'true' 'false'"/>
      <classpath refid="project.class.path"/>
    </java>
    <!--java classname="org.openbravo.erpCommon.utility.CommandLine_CopyFiles" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
      <arg line="'${base.config}/XmlPool.xml' '${basedir}' '${base.design}' 'fo' 'true' 'false'"/>
      <classpath refid="project.class.path"/>
    </java>
    <java classname="org.openbravo.erpCommon.utility.CommandLine_CopyFiles" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
      <arg line="'${base.config}/XmlPool.xml' '${basedir}' '${base.design}' 'html' 'true' 'false'"/>
      <classpath refid="project.class.path"/>
    </java>
    <java classname="org.openbravo.erpCommon.utility.CommandLine_CopyFiles" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
      <arg line="'${base.config}/XmlPool.xml' '${basedir}' '${base.design}' 'srpt' 'true' 'false'"/>
      <classpath refid="project.class.path"/>
    </java>
    <java classname="org.openbravo.erpCommon.utility.CommandLine_CopyFiles" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
      <arg line="'${base.config}/XmlPool.xml' '${basedir}' '${base.design}' 'jrxml' 'true' 'false'"/>
      <classpath refid="project.class.path"/>
    </java-->
    <java classname="org.openbravo.erpCommon.utility.CommandLine_CopyFiles" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
      <arg line="'${base.config}/XmlPool.xml' '${basedir}' '${base.design}' 'jasper' 'true' 'false'"/>
      <classpath refid="project.class.path"/>
    </java>
  </target>

  <target name="compile.src" depends="compileSqlc, postsrc, copy.files">
    <!--antcall inheritall="true" inheritrefs="true" target="compile.translate">
      <param name="extension" value="html"/>
    </antcall>
    <antcall inheritall="true" inheritrefs="true" target="compile.translate">
      <param name="extension" value="fo"/>
    </antcall-->
  </target>

  <target name="compile" depends="wad,compileSqlc, postsrc, translate">
  </target>

  <target name="compile.complete" depends="clean,wad,compileSqlc,postsrc, translate">
    <!--antcall inheritall="true" inheritrefs="true" target="compile.translate">
      <param name="extension" value="html"/>
    </antcall>
    <antcall inheritall="true" inheritrefs="true" target="compile.translate">
      <param name="extension" value="fo"/>
    </antcall-->
  </target>

  <target name="translate">
    <antcall inheritall="true" inheritrefs="true" target="compile.translate">
      <param name="extension" value="html"/>
    </antcall>
    <antcall inheritall="true" inheritrefs="true" target="compile.translate">
      <param name="extension" value="fo"/>
    </antcall>
    <antcall inheritall="true" inheritrefs="true" target="compile.translate">
      <param name="extension" value="srpt"/>
    </antcall>
    <antcall inheritall="true" inheritrefs="true" target="compile.translate">
      <param name="extension" value="jrxml"/>
    </antcall>
  </target>

  <target name="compile.translate">
    <java classname="org.openbravo.translate.Translate" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
      <arg line="${base.config}${separator}XmlPool.xml ${extension} ${basedir} ${base.design} ${package}"/>
      <classpath refid="project.class.path"/>
    </java>
  </target>

  <target name="installWebService" depends="init" if="wsdd">
    <java classname="org.apache.axis.client.AdminClient" fork="yes" jvm="${env.JAVA_HOME}/bin/java" maxmemory="${build.maxmemory}">
      <arg line="-l${context.url}/servlet/AxisServlet ${src}/deploy.wsdd"/>
      <classpath refid="project.class.path"/>
    </java>
  </target>

  <target name="uninstallWebService" depends="init">
    <java classname="org.apache.axis.client.AdminClient" fork="yes" jvm="${env.JAVA_HOME}/bin/java" maxmemory="${build.maxmemory}">
      <arg line="-l${context.url}/servlet/AxisServlet ${src}undeploy.wsdd"/>
      <classpath refid="project.class.path"/>
    </java>
  </target>

  <target name="copy.files">
    <chmod dir="${build}/src" perm="755"/>
    <mkdir dir="${jakarta.base}/webapps/${context.name}"/>
    <copy todir="${jakarta.base}/webapps/${context.name}"  encoding="UTF-8">
      <fileset file="${basedir}/index.html"/>
    </copy>
    <mkdir dir="${jakarta.base}/webapps/${context.name}/src-loc"/>
    <copy todir="${jakarta.base}/webapps/${context.name}/src-loc"  encoding="UTF-8">
      <fileset dir="${base.design}"/>
    </copy>
    <mkdir dir="${jakarta.base}/webapps/${context.name}/WEB-INF"/>
    <copy todir="${jakarta.base}/webapps/${context.name}/WEB-INF"  encoding="UTF-8">
      <fileset file="${build.sqlc}/src/web.xml"/>
      <fileset dir="${base.config}"/>
    </copy>
    <mkdir dir="${jakarta.base}/webapps/${context.name}/WEB-INF/lib"/>
    <copy todir="${jakarta.base}/webapps/${context.name}/WEB-INF/lib"  encoding="UTF-8">
      <fileset dir="${base.lib}">
        <exclude name="openbravo-wad.jar"/>
        <exclude name="openbravo-trl.jar"/>
        <exclude name="*.war"/>
      </fileset>
    </copy>
    <mkdir dir="${jakarta.base}/webapps/${context.name}/WEB-INF/classes"/>
    <copy todir="${jakarta.base}/webapps/${context.name}/WEB-INF/classes" encoding="UTF-8">
      <fileset dir="${build}/src"/>
    </copy>
    <mkdir dir="${jakarta.base}/webapps/${context.name}/web"/>
    <copy todir="${jakarta.base}/webapps/${context.name}/web"  encoding="UTF-8">
      <fileset dir="${base.subversion}/web/"/>
    </copy>
    <chmod dir="${jakarta.base}/webapps/${context.name}" perm="775"/>
  </target>

  <target name="compile.development" depends="compile, copy.files">
  </target>

  <target name="compile.complete.development" depends="compile.complete, copy.files">
  </target>

  <target name="build.war">
    <chmod dir="${build}/src" perm="755"/>
    <delete failonerror="false" file="${base.lib}/${context.name}.war"/>
    <war compress="true" destfile="${base.lib}/${context.name}.war" encoding="UTF-8" webxml="${build.sqlc}/src/web.xml">
      <!--fileset dir="src/jsp/myapp"/-->
      <fileset file="${basedir}/index.html"/>
      <lib dir="${base.lib}">
        <exclude name="openbravo-wad.jar"/>
        <exclude name="openbravo-trl.jar"/>
	<exclude name="servlet-api.jar"/>
      </lib>
      <classes dir="${build}/src"/>
      <zipfileset dir="${base.subversion}/web" 
                  prefix="web"/>
      <zipfileset dir="${base.config}" 
                  prefix="WEB-INF"/>
      <zipfileset dir="${base.design}" 
                  prefix="src-loc"/>
    </war>
  </target>
</project>
